home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / alv.sun / alv.lha / src / ras2array.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-08  |  2.2 KB  |  82 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3.  
  4. har           *progname;
  5. har           *filename;
  6. ixrect        *pr;
  7.  
  8. #ifdef STANDALONE
  9. ain(argc, argv, envp)
  10. #else
  11. as2array_main(argc, argv, envp)
  12. #endif
  13.     int             argc;
  14.     char          **argv;
  15.     char          **envp;
  16. {
  17.     register int    x, y;
  18.     short          *shortimage, *shortptr;
  19.     unsigned char  *charimage, *charptr;
  20.     long           *longimage, *longptr;
  21.  
  22.     progname = strsave(argv[0]);
  23.     parse_profile(&argc, argv, envp);
  24.  
  25.     while ((gc = getopt(argc, argv, " ")) != EOF)
  26.         switch (gc) {
  27.         case '?':
  28.             errflag++;
  29.             break;
  30.         }
  31.  
  32.     if (errflag)
  33.         error((char *) 0, "Usage: %s: [infile] [outfile]\n", progname);
  34.  
  35.     for (stream = 0; optind < argc; stream++, optind++)
  36.         if (stream < 2 && strcmp(argv[optind], "-") != 0)
  37.             if (freopen(argv[optind], mode[stream], f[stream]) == NULL)
  38.                 error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
  39.  
  40.     if ((pr = pr_load(stdin, NULL)) == NULL)
  41.         error(PR_IO_ERR_RASREAD);
  42.  
  43.     switch (pr->pr_depth) {
  44.     case 8:
  45.         charimage = (unsigned char *) malloc(sizeof(unsigned char) * pr->pr_size.x);
  46.         for (y = 0; y < pr->pr_size.y; y++) {
  47.             charptr = charimage;
  48.             for (x = 0; x < pr->pr_size.x; x++)
  49.                 *charptr++ = (char) pr_get(pr, x, y);
  50.             if (fwrite(charimage, sizeof(*charimage), pr->pr_size.x, stdout) != pr->pr_size.x)
  51.                 error("Error writing image data (possible file size error)");
  52.         }
  53.         free(charimage);
  54.         break;
  55.     case 16:
  56.         shortimage = (short *) malloc(sizeof(short) * pr->pr_size.x);
  57.         for (y = 0; y < pr->pr_size.y; y++) {
  58.             shortptr = shortimage;
  59.             for (x = 0; x < pr->pr_size.x; x++)
  60.                 *shortptr++ = (short) pr_get(pr, x, y);
  61.             if (fwrite(shortimage, sizeof(*shortimage), pr->pr_size.x, stdout) != pr->pr_size.x)
  62.                 error("Error writing image data (possible file size error)");
  63.         }
  64.         free(shortimage);
  65.         break;
  66.     case 24:
  67.         error("Don't know how to write 24 bit images");
  68.         break;
  69.     case 32:
  70.         longimage = (long *) malloc(sizeof(long) * pr->pr_size.x);
  71.         for (y = 0; y < pr->pr_size.y; y++) {
  72.             longptr = longimage;
  73.             for (x = 0; x < pr->pr_size.x; x++)
  74.                 *longptr++ = (long) pr_get(pr, x, y);
  75.             if (fwrite(longimage, sizeof(*longimage), pr->pr_size.x, stdout) != pr->pr_size.x)
  76.                 error("Error writing image data (possible file size error)");
  77.         }
  78.         free(longimage);
  79.         break;
  80.     }
  81. }
  82.